<template>
	<!-- 添加车辆 -->
	<view class="addCar">
		<u-navbar title="修改收货地" title-color="#333" back-icon-color="#333"></u-navbar>
		<view class="addCar-bottom">
			<view class="addCar-content-box">
				<!--  -->
				<view class="addCar-carName-phone" @click="getLocation">
					<text class="addCar-phone">收货地：</text>
					<input style="width: 70%;" class="addCar-input-one" type="text" disabled="disabled" placeholder="点击添加收货地" v-model="nameIpt"/>
					<image class="loa_img_icon" src="../../static/images/loa-icon.png" mode=""></image>
				</view>
				<!-- <view class="addCar-carName-phone">
					<text class="addCar-phone">收货地：</text>
					<input style="width: 70%;" class="addCar-input-one" type="text"  placeholder="输入收货地" v-model="nameIpt"/>
				</view> -->
				<view class="addCar-carName-phone">
					<p class="addCar-phone">详细地址：</p>
					<p style="width: 70%;">{{nameIptAdres}}</p>
					
				</view>
				<!-- <view class="addCar-carName-phone">
					<text class="addCar-phone">收货地：</text>
					<input style="width: 70%;" class="addCar-input-one" type="text"  placeholder="输入详细收货地" v-model="namexxIptAdres"/>
				</view> -->
				

				<!-- <view class="addCar-carName-phone">
					<text class="addCar-phone">运费单价：</text>
					<input class="addCar-input-one" type="text" @input="DPFreightAddUp" placeholder="请输入运费单价" v-model="phoneIpt"
					 maxlength="9" />
				</view> -->
			</view>
			<!-- <view class="zhu_text">
				<text>注：填写收货地时，请详细到某商砼站或者某工地</text>
			</view> -->
			<!--  -->
			<view class="addCar-reset-determine">
				<view class="addCar-reset" @click="reset">重置</view>
				<view class="addCar-determine" @click="determine">确定</view>
			</view>
		</view>
		<u-modal v-model="addCarLoginShow" content="请确认是否修改该配送地" :show-cancel-button="true" @confirm="addCarConfirm"></u-modal>
	</view>
</template>

<script>
	import {
		checkOpenGPSServiceByAndroid
	} from '../../util/map.js';
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				latitude: 0,
				longitude: 0,
				addressNew: null,
				Index: 0,
				iteminfo:'',
				inititem:'',
				nameIpt: '', //车主姓名
				phoneIpt: '', //联系方式
				addCarLoginShow: false,
				nameIptAdres:'',
				namexxIptAdres:''
				
			}
		},
		onLoad(option) {
			this.inititem=option.item
			this.iteminfo=JSON.parse(option.item)
			console.log(this.iteminfo)
			this.nameIpt=this.iteminfo.ORMTB404CA00
			this.nameIptAdres = this.iteminfo.ORMTB404CA05
			// this.namexxIptAdres = this.iteminfo.ORMTB404CA05
			this.longitude = this.iteminfo.ORMTB404CA06
			this.latitude = this.iteminfo.ORMTB404CA07
			this.phoneIpt=this.iteminfo.ORMTB404CA01
		},
		methods: {
			
			getLocation() {
				checkOpenGPSServiceByAndroid()
						this.getmasgpoi()
				// uni.getLocation({
				// 	type: 'gcj02',
				// 	success: res => {
				// 		let {
				// 			latitude,
				// 			longitude
				// 		} = res;
				// 		// 设置中心
				// 		this.latitude = latitude;
				// 		this.longitude = longitude;
				// 		// this.getmasgpoi()
						
				// 	}
				// });
			},
			getmasgpoi(){
				// let _this = this
				// var currentUrl = location.href;
				// console.log(currentUrl); // 输出当前页面的URL
				// return
				// let txMapUrl = `https://apis.map.qq.com/tools/locpicker?search=1&type=0&backurl=/pages/deliveryPlaceAdd/index&key=3NYBZ-WRL3Z-V3VXL-ZYUPM-SSP6J-S2BBJ&referer=myapp`
				let self = this
				// 监听选定事件
				uni.$once('locateOk',function(data){
					console.log('监听到事件来自 locateOk ，携带参数 data 为：', data);
					self.nameIptAdres = data.address
					self.latitude = data.latitude
					self.longitude = data.longitude
					self.nameIpt = data.poiname
				})
				uni.navigateTo({
					url: `/pages/webmap/mappoi/index?mapKey=${this.mapKey}`
				
				});
				// uni.chooseLocation({
				// 	latitude: _this.latitude,
				// 	longitude: _this.longitude,
				// 	keyword:_this.nameIpt,
				// 	success:function(res){
				// 		console.log(res)
				// 		console.log(res.name)
				// 		_this.nameIpt = res.name
				// 		_this.nameIptAdres = res.address
				// 		_this.latitude = res.latitude
				// 		_this.longitude = res.longitude
				// 	},
				// 	fail:function(fail){
				// 		uni.showToast({
				// 			title: '位置获取失败',
				// 			duration: 5000,
				// 			icon: 'none',
				// 		});
				// 	}
				// })
			},
			
			//配送单价
			DPFreightAddUp() {
				var value = this.phoneIpt;
				var num = this.clearNoNum(value);
				console.log(num)
				if(num<=0) return
				if(num>100000){
					uni.showToast({
						title: '单价高于最大限制100000',
						duration: 5000,
						icon: 'none',
					});
				}
				num=num>100000?100000:num
				this.$nextTick(function(){
					this.phoneIpt=num
				})
			},
			clearNoNum(value) {
				value = value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
				value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
				value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
				if (value.indexOf(".") < 0 && value != "") { //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
					value = parseFloat(value);
				}
				return value;
			},
			// 确定
			determine() {
				if(this.nameIpt.trim()==''){
					uni.showToast({
						title: '收货地不可为空',
						duration: 5000,
						icon: 'none',
					});
					return 
				}
				// if(this.phoneIpt===''){
				// 	uni.showToast({
				// 		title: '运费单价不可为空',
				// 		duration: 5000,
				// 		icon: 'none',
				// 	});
				// 	return
				// }
				this.addCarLoginShow = true
			},
			addCarConfirm() {
				if(this.userinfo.sign=='CUS-1'){
					var ORMTB400ID=this.userinfo.ORMTB400ID
				}else if(this.userinfo.sign=='CUS-2'||this.userinfo.sign=='CUS-3'){
					var ORMTB400ID=this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb404/update',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB404ID: this.iteminfo.ORMTB404ID,
						ORMTB400ID:ORMTB400ID,
						ORMTB404CA00: this.nameIpt,
						ORMTB404CA05:this.nameIptAdres,
						ORMTB404CA06:this.longitude,
						ORMTB404CA07:this.latitude,
						// ORMTB404CA01: this.phoneIpt,
						sign: this.userinfo.sign,
					},
					success: (res) => {
						// console.log(res);
						if (res.data.code == 200) {
							uni.showToast({
								title: '修改成功',
								duration: 5000,
								icon: 'none',
							});
							uni.navigateBack({
								delta:1
							})
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: res.data.errMsg,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			// 重置
			reset() {
				
				this.nameIpt = '' //收货地
				
				this.nameIptAdres = '' //详细收货地
				// this.namexxIptAdres = '' //详细收货地
			},
		}
	}
</script>

<style scoped>
	.addCar input {
		border: 0;
	}

	.addCar {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(242, 242, 242, 1);
		overflow: hidden;
	}

	/* 列表 */

	/* 内容 */
	.addCar-content-box {
		width: 100%;
		background: rgba(255, 255, 255, 1);
		padding: 0 24rpx;
	}

	.addCar-carName-phone {
		border-bottom: 2rpx solid rgba(230, 230, 230, 1);
		padding: 18rpx 0;
		display: flex;
	}

	.addCar-input-one {
		/* width: 310rpx !important; */
		display: inline-block;
		margin-bottom: 0 !important;
		padding: 0 !important;
		height: 44rpx !important;
		/* margin-left: 0.1rem; */
		color: rgba(51, 51, 51, 1);
		/* font-size: 28rpx; */
		text-align: center;
	}

	.addCar-phone {
		/* width: 238rpx; */
		display: inline-block;
		font-size: 30rpx;
		color: rgba(102, 102, 102, 1);
		/* background: #000000; */
	}

	.addCar-phone-placeholder {
		font-size: 30rpx;
		color: rgba(102, 102, 102, .5);
	}

	.addCar-dun {
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
	}

	/* 按钮 */
	.addCar-reset-determine {
		margin-top: 167rpx;
		display: flex;
	}

	.addCar-reset-determine>view {
		width: 159rpx;
		text-align: center;
		line-height: 65rpx;
		color: rgba(255, 255, 255, 1);
		font-size: 32rpx;
	}

	.addCar-reset {
		width: 159rpx;
		background: rgba(234, 197, 15, 1);
		text-align: center;
		margin-left: 170rpx;
	}

	.addCar-determine {
		background: rgba(0, 161, 244, 1);
		margin-left: 60rpx;
	}

	.addCar-phone-car {
		display: inline-block;
		width: 310rpx;
		height: 44rpx;
		line-height: 44rpx;
		/* border: 1px solid rgba(0, 0, 0, .2); */
		/* border-radius: 3px; */
		text-align: center;
		vertical-align: middle;
		font-size: 30rpx;
	}

	input::placeholder {
		color: rgba(102, 102, 102, .5);
	}
	.loa_img_icon{
		width: 40rpx;
		height: 40rpx;
	}
	.zhu_text{
		color: red;
		padding: 24rpx;
	}
</style>
